CREATE TABLE [dbo].[Aluno] (
    [alu_cod_matricula] INT          NOT NULL PRIMARY KEY CLUSTERED ([alu_cod_matricula] ASC),
    [alu_nome]          VARCHAR (30) NOT NULL,
    [alu_cod_ata]       INT          NOT NULL,
    [alu_cod_materia]   INT          NOT NULL,
    FOREIGN KEY ([alu_cod_ata]) REFERENCES [dbo].[Ata] ([ata_codigo]),
    FOREIGN KEY ([alu_cod_materia]) REFERENCES [dbo].[Materia] ([mat_codigo])
);

GO
CREATE TABLE [dbo].[Ata] (
    [ata_codigo]      INT  NOT NULL PRIMARY KEY CLUSTERED ([ata_codigo] ASC),
    [data]            DATE NOT NULL,
    [ata_cod_aluno]   INT  NOT NULL,
    [ata_cod_materia] INT  NOT NULL,
    FOREIGN KEY ([ata_cod_aluno]) REFERENCES [dbo].[Aluno] ([alu_cod_matricula]),
    FOREIGN KEY ([ata_cod_materia]) REFERENCES [dbo].[Materia] ([mat_codigo])
);

GO
CREATE TABLE [dbo].[Endereco] (
    [end_codigo] INT        NOT NULL PRIMARY KEY CLUSTERED ([end_codigo] ASC),
    [end_rua]    NCHAR (10) NOT NULL,
    [end_numero] NCHAR (10) NULL,
    [end_cidade] NCHAR (10) NOT NULL,
    [end_estado] NCHAR (10) NOT NULL
);

GO
CREATE TABLE [dbo].[Escola] (
    [esc_cod]          INT          NOT NULL PRIMARY KEY CLUSTERED ([esc_cod] ASC),
    [esc_nome]         VARCHAR (40) NOT NULL,
    [esc_telefone]     INT          NOT NULL,
    [esc_cod_endereco] INT          NOT NULL,
    FOREIGN KEY ([esc_cod_endereco]) REFERENCES [dbo].[Endereco] ([end_codigo])
);

GO
CREATE TABLE [dbo].[Materia] (
    [mat_codigo]     INT          NOT NULL PRIMARY KEY CLUSTERED ([mat_codigo] ASC),
    [mat_nome]       VARCHAR (20) NOT NULL,
    [mat_turma]      VARCHAR (10) NOT NULL,
    [mat_descricao]  VARCHAR (30) NOT NULL,
    [mat_cod_escola] INT          NOT NULL,
    FOREIGN KEY ([mat_cod_escola]) REFERENCES [dbo].[Escola] ([esc_cod])
);

GO
CREATE TABLE [dbo].[Table1] (
    [prof_matricula] INT          NOT NULL PRIMARY KEY CLUSTERED ([prof_matricula] ASC),
    [prof_nome]      VARCHAR (30) NOT NULL,
    [prof_email]     VARCHAR (30) NOT NULL
);

GO
